#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@File: MaxKbApi.py
@Author: lijk34925 
@Date: 2025/4/17 15:56
@desc: 请补充本模块功能说明
"""

import requests


class MaxKbApi:
    def __init__(self):
        self.apiKey = 'application-86514f3c85a59f0e565658294aea38a3'
        self.base_url = "http://10.20.181.127:8087"
        self.app_no = "d7a4e468-102f-11f0-9f1a-0242ac130003"
        self.current_session_id = None
        self.headers = {
            "Content-Type": "application/json",
            "Authorization": self.apiKey
        }

    def open_session(self):
        url = f"{self.base_url}/api/application/{self.app_no}/chat/open"
        response = requests.get(url, headers=self.headers)
        self.current_session_id = response.json()['data']

    def get_knowledge(self, question):
        url = f"{self.base_url}/api/application/chat_message/{self.current_session_id}"
        print(f"url: {url}")

        payload = {
            "message": question,
            "re_chat": "false",
            "stream": "false",
            "document_list": [],
            "image_list": [],
            "audio_list": [],
            "video_list": [],
            "form_data": {}
        }
        response = requests.post(url, json=payload, headers=self.headers)
        print(response.json())
        content = response.json()['data']['content']
        return content


# 示例用法
if __name__ == "__main__":
    MX = MaxKbApi()
    MX.open_session()
    res = MX.get_knowledge("")
    print(f"==============")
    print(res)

